﻿using System;
using System.Web;
using BusinessObject;
using Model;

namespace ViewLayer.Account
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
        }

        protected void LoginUser_Authenticate(object sender, System.Web.UI.WebControls.AuthenticateEventArgs e)
        {
            try
            {
                User user = UserBO.Instance.RecoverUser(LoginUser.UserName, LoginUser.Password);

                if (user != null)
                {
                    HttpContext.Current.Session.Add("User", user);
                    Response.Redirect("../Pages/Default.aspx");
                    e.Authenticated = true;
                }
                else
                {
                    e.Authenticated = false;                    
                    LoginUser.FailureText = "Login Inválido";
                }
            }
            catch
            {
            }
        }
    }
}